// vim:ft=javascript

var DS_EXT_NAME="ds";
var DS_EXT_DIR=configure_module_dirname + "/src";
var DS_EXT_API="php_ds.c";
var DS_EXT_FLAGS="/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 /I" + configure_module_dirname;

function ds_src(dir, files) {
    return ADD_SOURCES(
        DS_EXT_DIR + dir,
        files.join(" "),
        DS_EXT_NAME
    );
}

////////////////////////////////////
ARG_ENABLE("ds", "for extended data structure support", "no");

if (PHP_DS != "no") {
    EXTENSION(DS_EXT_NAME, DS_EXT_API, PHP_DS_SHARED, DS_EXT_FLAGS);

    ds_src("/",
    [
        "common.c"
    ]);

    ds_src("/ds",
    [
        "ds_deque.c",
        "ds_vector.c",
        "ds_htable.c",
        "ds_set.c",
        "ds_map.c",
        "ds_stack.c",
        "ds_priority_queue.c",
        "ds_queue.c",
    ]);

    ds_src("/php/objects",
    [
        "php_deque.c",
        "php_vector.c",
        "php_map.c",
        "php_pair.c",
        "php_priority_queue.c",
        "php_set.c",
        "php_stack.c",
        "php_queue.c",
    ]);

    ds_src("/php/iterators",
    [
        "php_vector_iterator.c",
        "php_deque_iterator.c",
        "php_set_iterator.c",
        "php_map_iterator.c",
        "php_stack_iterator.c",
        "php_htable_iterator.c",
        "php_priority_queue_iterator.c",
        "php_queue_iterator.c",
    ]);

    ds_src("/php/handlers",
    [
        "php_common_handlers.c",
        "php_vector_handlers.c",
        "php_deque_handlers.c",
        "php_set_handlers.c",
        "php_map_handlers.c",
        "php_stack_handlers.c",
        "php_pair_handlers.c",
        "php_priority_queue_handlers.c",
        "php_queue_handlers.c",
    ]);

    ds_src("/php/classes",
    [
        "php_hashable_ce.c",
        "php_collection_ce.c",
        "php_sequence_ce.c",
        "php_vector_ce.c",
        "php_deque_ce.c",
        "php_set_ce.c",
        "php_map_ce.c",
        "php_stack_ce.c",
        "php_pair_ce.c",
        "php_priority_queue_ce.c",
        "php_queue_ce.c",
    ]);

    ADD_EXTENSION_DEP('ds', 'spl');
    var dll = get_define('PHPDLL');
    if (null != dll.match(/^php7/)) {
        // only require dynamic json extension for PHP 7
        // json is built statically in PHP 8
        // https://github.com/php/php-src/pull/5495
        ADD_EXTENSION_DEP('ds', 'json');
    }
}
